/*
 * @Author: Bennent_G
 * @Date: 2025-01-02 12:14:48
 * @LastEditTime: 2025-01-17 11:22:28
 * @Description:
 */
// src/hooks/useRouteInfo.ts
import { ref, watch, computed } from 'vue';
import { useRoute } from 'vue-router';

export default function useRouteHook() {
	const route = useRoute();
	const currentRoute = ref(route);

	const parentRoute = computed(() => {
		const matchedRoutes = route.matched;
		if (matchedRoutes.length > 1) {
			return matchedRoutes[matchedRoutes.length - 2];
		}
		return null;
	});

	watch(
		() => route.path,
		(newPath) => {
			currentRoute.value = route;
			console.log('路由变化:', newPath);
			// console.log('当前路由:', currentRoute.value);
			// console.log('父级路由:', parentRoute.value);
		},
		{ immediate: true }
	);

	return {
		currentRoute,
		parentRoute,
	};
}
